package com.masterclient.app.modules.income.adapter;

import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.masterclient.app.R;
import com.masterclient.app.modules.income.model.ProfitsTypeChildBean;
import com.masterclient.app.utils.TransformationFixedImage;
import com.eoner.baselibrary.utils.Utils;

/**
 * @auther hjian
 * @date 2020/6/15.
 */
public class ProfitEarnAdapter extends BaseQuickAdapter<ProfitsTypeChildBean, BaseViewHolder> {

    private OnClickImgListener onClickImgListener;

    public ProfitEarnAdapter(OnClickImgListener onClickImgListener) {
        super(R.layout.item_profit_earn);
        this.onClickImgListener = onClickImgListener;
    }

    public interface OnClickImgListener{
        void onClickImg();
    }

    @Override
    protected void convert(BaseViewHolder helper, ProfitsTypeChildBean item) {

        View itemProfitEarnPoint = helper.getView(R.id.item_profit_earn_point);
        boolean isZero = TextUtils.isEmpty(item.getProfits()) || Double.parseDouble(item.getProfits())<=0;
        if ("0".equals(item.getIncomeType())){
            itemProfitEarnPoint.setBackgroundResource(isZero?R.drawable.shape_rounds_999faa:R.drawable.shape_round_ffe116);
        }else if ("1".equals(item.getIncomeType())){
            itemProfitEarnPoint.setBackgroundResource(isZero?R.drawable.shape_rounds_999faa:R.drawable.shape_round_ff3b64);
        }else if ("2".equals(item.getIncomeType())){
            itemProfitEarnPoint.setBackgroundResource(isZero?R.drawable.shape_rounds_999faa:R.drawable.shape_round_a35dff);
        }else if ("3".equals(item.getIncomeType())){
            itemProfitEarnPoint.setBackgroundResource(isZero?R.drawable.shape_rounds_999faa:R.drawable.shape_round_ffb43b);
        }
        ImageView imageView = helper.getView(R.id.item_profit_earn_icon);
        imageView.setOnClickListener(v -> {
            onClickImgListener.onClickImg();
        });
        Glide.with(mContext)
                .asBitmap()
                .load(item.getIcon())
                .apply(new RequestOptions().placeholder(R.color.transparent))
                .into(new TransformationFixedImage(imageView));


        TextView itemProfitEarnTitle = helper.getView(R.id.item_profit_earn_title);
        TextView itemProfitEarnTotal = helper.getView(R.id.item_profit_earn_total);
        TextView itemProfitEarnDetail = helper.getView(R.id.item_profit_earn_detail);

        itemProfitEarnTitle.setText(item.getTitle());
        itemProfitEarnTitle.setTextColor(isZero?0xFF999FAA:0xFF141922);
        Utils.setDin(itemProfitEarnTotal, mContext);
        itemProfitEarnTotal.setText(TextUtils.isEmpty(item.getProfits())?"0.00":item.getProfits());
        itemProfitEarnTotal.setTextColor(isZero?0xFF999FAA:0xFF141922);
        itemProfitEarnDetail.setTextColor(isZero?0xFF555A68:0xFF141922);
        itemProfitEarnDetail.setText(item.getSub_title());
    }
}
